<?php
/**
 * @authors alex (20779512@qq.com)
 * @date    2014-03-24 17:25:39
 * @version 1.0
 */

class MyuserAction extends HomeAction {

    public function index(){

        $level = I('get.level',1);

        $obj = M('Member');

        //一级会员
        if ($level==1) {
            $map['fid'] = $this->_user['wxid'];
            $count = $obj->where($map)->count();
            import("@.ORG.WapPage");
            $page = new Page($count, 10);
            $show = $page->show();
            $list = $obj->where($map)->order('money desc')->limit($page->firstRow . ',' . $page->listRows)->select();
        }

        //二级会员
        if ($level==2) {
            $map['fid'] = $this->_user['wxid'];     
            $list = M('Member')->where($map)->getField('id,wxid');

            unset($map);
            $map['fid'] = array('in',$list);
            $count = $obj->where($map)->count();
            import("@.ORG.WapPage");
            $page = new Page($count, 10);
            $show = $page->show();
            $list = $obj->where($map)->order('money desc')->limit($page->firstRow . ',' . $page->listRows)->select();
        }

        //三级会员
        if ($level==3) {
            $map['fid'] = $this->_user['wxid'];
            $list = M('Member')->where($map)->getField('id,wxid');

            unset($map);
            $map['fid'] = array('in',$list);
            $list = M('Member')->where($map)->getField('id,wxid');

            unset($map);
            $map['fid'] = array('in',$list);
            $count = $obj->where($map)->count();
            import("@.ORG.WapPage");
            $page = new Page($count, 10);
            $show = $page->show();
            $list = $obj->where($map)->order('money desc')->limit($page->firstRow . ',' . $page->listRows)->select();
        }        

        $this->assign('level', $level);
        $this->assign('list', $list);
        $this->assign('page', $show);
        $this->display();
    }
}